package cn.hrlly.tao2shou.biz;

import android.content.Context;

import com.zhy.http.okhttp.OkHttpUtils;

import cn.hrlly.tao2shou.other.Config;
import cn.hrlly.tao2shou.callback.PublishCommoditiesListCallBack;
import cn.hrlly.tao2shou.domain.CommodityList;
import cn.hrlly.tao2shou.listener.OnPublishCommoditiesListListener;
import cn.hrlly.tao2shou.utils.CacheUtil;

/**
 * User: gengliang
 * Date: 2016-01-28
 * Time: 14:10
 */

public class PublishCommoditiesListBizImpl implements PublishCommoditiesListBiz {

    private OnPublishCommoditiesListListener onPublishCommoditiesListListener;
    private CacheUtil cacheUtil;

    public PublishCommoditiesListBizImpl(OnPublishCommoditiesListListener onPublishCommoditiesListListener,Context context){
        this.onPublishCommoditiesListListener=onPublishCommoditiesListListener;
        this.cacheUtil=new CacheUtil(context);
    }

    @Override
    public void publishCommoditiesList() {
        OkHttpUtils
                .post()
                .url(Config.key_url)
                .addParams(Config.key_action,Config.action_publish_commodities_list)
                .build()
                .execute(new PublishCommoditiesListCallBack(onPublishCommoditiesListListener));
    }

    @Override
    public void saveCachePublishCommoditiesList(CommodityList commodityList) {
        cacheUtil.putPublishCommodity(commodityList);
    }

    @Override
    public CommodityList getCachePublishCommoditiesList() {
        CommodityList commodityList=cacheUtil.getPublishCommodity();
        return commodityList;
    }
}
